<%@page contentType="text/html;charset=utf-8"%>
<%@include file="../../core/common.jsp"%>
<html>
<head>
<title></title>
</head>
<script>
	var users = $.loadOption('${CTX}/mgt/sys/user/option');
	function user_(value, row, index) {
		return users[value];
	}
	var rkzts = $.loadOption('${CTX}/mgt/sys/dict/option/rkzt');
	function rkzt_(value, row, index) {
		return rkzts[value];
	}
	function dy_(value, row, index) {
		var a = '';
		if (row.rkzt == '20') {
			var page = 1;
			var rows = 3;
			for (var i = 0; i < row.kqmc.length; i++) {
				if (i % rows == 0) {
					a += '<a href="${CTX}/mgt/t/rkd/dy?cpbh=' + row.cpbh + '&rows=' + rows + '&page=' + page + '" class="m-r-20">第' + page + '页</a>';
					page++;
				}
			}
		}
		return a;
	}
</script>
<body>
	<div id="tb" class="toolbar">
		<form id="fm">
			<table class="form-layout w80">
				<tr>
					<td>产品编号：</td>
					<td><input name="search_cpbh" class="easyui-textbox" /></td>
					<td>规格型号：</td>
					<td><input name="search_ggxh" class="easyui-combobox" data-options="url:'${CTX}/mgt/sys/dict/value/ph',editable:false,formatter:''" /></td>
					<td>入库期起：</td>
					<td><input name="search_begin" class="easyui-datebox" data-options="editable:false" /></td>
					<td>入库期止：</td>
					<td><input name="search_end" class="easyui-datebox" data-options="editable:false" /></td>
				</tr>
			</table>
		</form>
		<div style="float: left;">
			<shiro:hasPermission name="rkd:wcrk">
				<a id="wcrk" class="form-btn success">
					<i class="fa fa-check m-r-5"></i>完成入库
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="rkd:qxwc">
				<a id="qxwc" class="form-btn warning">
					<i class="fa fa-undo m-r-5"></i>取消完成
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="rkd:xgrkd">
				<a id="xgrkd" class="form-btn primary">
					<i class="fa fa-pencil-square-o m-r-5"></i>修改入库单
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="rkd:xgrkmx">
				<a id="xgrkmx" class="form-btn primary">
					<i class="fa fa-pencil-square-o m-r-5"></i>修改入库明细
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="rkd:dyrkmx">
				<a id="dyrkmx" class="form-btn primary">
					<i class="fa fa-print m-r-5"></i>打印入库明细
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="rkd:download">
				<a id="download" class="form-btn success">
					<i class="fa fa-download m-r-5"></i>下载模版
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="rkd:upload">
				<a id="upload" class="form-btn success">
					<i class="fa fa-upload m-r-5"></i>批量上传
				</a>
			</shiro:hasPermission>
		</div>
		<div style="float: right;">
			<a id="find" class="form-btn success">
				<i class="fa fa-search m-r-5"></i>查询
			</a>
			<a id="reset" class="form-btn default">
				<i class="fa fa-undo m-r-5"></i>重置
			</a>
		</div>
		<div style="clear: both;"></div>
	</div>
	<table id="dg" class="easyui-datagrid" data-options="url:'${CTX}/mgt/t/rkd/find',toolbar:'#tb',pagination:true">
		<thead>
			<tr>
				<th data-options="field:'cpbh',width:100">产品编号</th>
				<th data-options="field:'ggxh',width:80">规格型号</th>
				<th data-options="field:'zl',width:80">重量(kg)</th>
				<th data-options="field:'ks',width:50">捆数</th>
				<th data-options="field:'rkzt',width:80,formatter:rkzt_">入库状态</th>
				<th data-options="field:'rkrq',width:100">入库日期</th>
				<th data-options="field:'rkry',width:80,formatter:user_">入库人员</th>
				<th data-options="field:'kqmc',width:200">库区名称</th>
				<th data-options="field:'dy',width:200,formatter:dy_">打印</th>
			</tr>
		</thead>
	</table>
</body>
<script>
	$(function() {
		$('#find').click(function() {
			$('#dg').datagrid('reload', $('#fm').serializeObject());
		});
		$('#reset').click(function() {
			$('#fm').form('reset');
			$('#find').click();
		});
		$('#wcrk').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.confirm('确认完成入库', function() {
					$.mask();
					$.ajax({
						url : '${CTX}/mgt/t/rkd/wcrk',
						data : {
							cpbh : row.cpbh
						},
						success : function(data) {
							$.unmask();
							$.handle(data, function() {
								$('#find').click();
							});
						}
					});
				});
			} else {
				$.info('请选择入库单');
			}
		});
		$('#qxwc').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.confirm('确认取消完成', function() {
					$.mask();
					$.ajax({
						url : '${CTX}/mgt/t/rkd/qxwc',
						data : {
							cpbh : row.cpbh
						},
						success : function(data) {
							$.unmask();
							$.handle(data, function() {
								$('#find').click();
							});
						}
					});
				});
			} else {
				$.info('请选择入库单');
			}
		});
		$('#xgrkd').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				if (row.rkzt != "20") {
					$.info('请选择已完成的入库单');
					return;
				}
				$.open({
					title : $(this).html(),
					url : '${CTX}/mgt/t/rkd/xgrkd?id=' + row.cpbh,
					end : function() {
						$('#find').click();
					}
				});
			} else {
				$.info('请选择入库单');
			}
		});
		$('#xgrkmx').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				if (row.rkzt != "20") {
					$.info('请选择已完成的入库单');
					return;
				}
				$.open({
					title : $(this).html(),
					url : '${CTX}/mgt/t/rkd/xgrkmx?id=' + row.cpbh,
					end : function() {
						$('#find').click();
					}
				});
			} else {
				$.info('请选择入库单');
			}
		});
		$('#dyrkmx').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				if (row.rkzt != '20') {
					$.info('请选择已完成的入库单');
					return;
				}
				$.open({
					title : $(this).html(),
					url : '${CTX}/mgt/t/rkd/dyrkmx?id=' + row.cpbh,
					end : function() {
						$('#find').click();
					}
				});
			} else {
				$.info('请选择入库单');
			}
		});
		$('#download').click(function() {
			window.location = '${CTX}/mgt/t/rkd/download';
		});
		$('#upload').click(function() {
			$.open({
				title : $(this).html(),
				url : '${CTX}/mgt/t/rkd/upload',
				end : function() {
					$('#find').click();
				}
			});
		});
	});
</script>
</html>